//
// Created by zhou on 2021/10/19.
//
#include <iostream>
#include <vector>
using namespace std;
class Solution{
public:
    int deleteAndEarn(vector<int> &nums){
        int maxval=0;
        for(int val:nums){
            maxval=max(maxval,val);
        }
        vector<int>x(maxval+1);
        int size=nums.size();
        for(int i=0;i<size;i++){
            x[nums[i]]+=nums[i];
        }
        if(maxval==1)return max(x[0],x[1]);
//        if(maxval==2)return max(x[0],x[1]);
        int first=x[0];
        int second=max(x[0],x[1]);
        for(int i=2;i<=maxval;i++){
            int tmp=max(second,first+x[i]);
            first=second;
            second=tmp;
        }
        return second;
    }
};
int main(){
    vector<int> nums={1,2,3,5,7};
    Solution solution;
    cout<<solution.deleteAndEarn(nums);
}